* clean raw survey data
********************************************************************************
* prelims
********************************************************************************
{
clear all
set more off
cap log close

}
********************************************************************************
* preclean demographic data 
********************************************************************************
{

* load data
import excel "$orig/survey/ticket_demographics.xlsx", sheet("Sheet1") cellrange(A2:E2453) allstring clear

* ticket
rename A ticket

* socio economic status
g SoEcStatusNET = .
replace SoEcStatusNET = 1 if B == "iE2"
replace SoEcStatusNET = 2 if B == "iE1"
replace SoEcStatusNET = 3 if B == "iD"
replace SoEcStatusNET = 4 if B == "iC"
replace SoEcStatusNET = 5 if B == "iB"
replace SoEcStatusNET = 6 if B == "iA2"
replace SoEcStatusNET = 7 if B == "iA1"

la def SoEcStatus 7 "iA1" 6 "iA2" 5 "iB" 4 "iC" 3 "iD" 2 "iE1" 1 "iE2"
la var SoEcStatusNET "Socio-Economic Status (Netquest Data)"
la val SoEcStatusNET SoEcStatus

drop B

* gender
g FemaleNET = (C=="Mujer")
la var FemaleNET "Female (Netquest Data)"
drop C

* ZIP Code
rename D PropZIPNET 
destring PropZIPNET, force replace
la var PropZIPNET "ZIP Code (Netquest Data)"

* age
rename E AgeNET
destring AgeNET, force replace
la var AgeNET "Age (Netquest Data)"

* store
compress
save "$data/temp/ticket_demographics.dta", replace

}
********************************************************************************
* clean survey data
********************************************************************************
{
* import raw survey data
import excel "$orig/survey/Perceived Inequality - Netquest.xlsx", sheet("Sheet0") firstrow clear
drop if _n==1

* add Netquest demographic data 
merge m:1 ticket using "$data/temp/ticket_demographics.dta"
drop _merge

* original time zone (GMT-7) 
* madrid is GMT+1
local 8hours = 1000*60*60*8 // # OF MILLISECONDS IN 8 HOURS
g double SurStart= clock(StartDate, "MD19Y hm") + `8hours'
g double SurEnd = clock(EndDate, "MD19Y hm") + `8hours'
format SurStart SurEnd %tc
order SurStart SurEnd
drop StartDate EndDate 
la var SurStart "Survey start date-time"
la var SurEnd "Survey end date-time"

* identify people that start the survey more than once
duplicates tag ticket, g(DupIDs)

* identify unique IDs
bys ticket: g FirstID = 1 if _n==1

* identify survey completed if duplicates
g DupFinished = (DupIDs>0 & Progress=="100")
g t_DupCompleted = 1 if (DupIDs>0 & Progress=="100" & regexm(ConsentFinal,"Sí, quiero")==1)
g t_DupNotAccept = 1 if (DupIDs>0 & Progress=="100" & regexm(ConsentFinal,"Sí, quiero")==0)

* these are people that stopped and then restarted
bys ticket: egen DupCompleted = mean(t_DupCompleted)
replace DupCompleted = 0 if DupCompleted == . & DupIDs>0
* these are people that stopped, restarted and finally did not accept
bys ticket: egen DupNotAccept = mean(t_DupNotAccept)
replace DupNotAccept = 0 if DupNotAccept == . & DupIDs>0
* these are people that stopped, restarted and finally dropped
g DupDropped = (DupCompleted==0 & DupNotAccept==0 & DupIDs>0)
replace DupDropped = . if DupIDs == 0

* count number of people that actually dropped
g Dropped = (Progress != "100")
replace Dropped = . if (DupDropped==1 & FirstID!=1)
replace Dropped = . if (DupDropped==0)
replace Dropped = 0 if (DupDropped==0 & FirstID==1)

* identify completed
g Completed = (Progress=="100" & regexm(ConsentFinal,"Sí, quiero")==1)
replace Completed = . if (DupCompleted==1 & Progress != "100")
replace Completed = . if DupIDs>0 & DupCompleted==0 & FirstID!=1

* identify Not Accept Conditons
g NotAccept = (Progress=="100" & regexm(ConsentFinal,"Sí, quiero")==0)
replace NotAccept = . if (DupNotAccept==1 & Progress != "100")
replace NotAccept = . if DupIDs>0 & DupNotAccept==0 & FirstID!=1

cap drop t_*

* identify participants dropping at the address question
g DropAddress = 1 if Dropped==1 & PropLocTime_PageSubmit == ""

* time
destring Durationinseconds ConsentTime_PageSubmit, force replace
g timesurvey = Durationinseconds - ConsentTime_PageSubmit
la var timesurvey "duration (seconds)"

* test
drop if ticket==""

* destring ZIP Code
destring PropZIP, force replace
destring Prop16yoZIP, force replace

* generate district (based on ZIP)
g ZIP = .

foreach var in SUR NET {

	if "`var'" == "SUR" {
		local var 
		replace ZIP = PropZIP`var'
	}
	else if "`var'" == "NET" {
		replace ZIP = PropZIP`var'
	}
	else if "`var'" == "16yo" {
		replace ZIP = Prop16yoZIP
	}

	g DistRough`var' = .
	replace DistRough`var' = 1 if ZIP>=8001 & ZIP <= 8003
	replace DistRough`var' = 2 if (ZIP>=8007 & ZIP<=8011|ZIP==8013|ZIP==8015|ZIP==8036)
	replace DistRough`var' = 3 if (ZIP==8004 | ZIP>=8038 & ZIP <= 8040)
	replace DistRough`var' = 4 if (ZIP==8014|ZIP==8034|ZIP==8028|ZIP==8029)
	replace DistRough`var' = 5 if (ZIP==8006|ZIP==8017|ZIP==8021|ZIP==8022)
	replace DistRough`var' = 6 if (ZIP==8025|ZIP==8012|ZIP==8023|ZIP==8024|ZIP==8037)
	replace DistRough`var' = 7 if (ZIP==8031|ZIP==8032|ZIP==8041|ZIP==8042|ZIP==8035)
	replace DistRough`var' = 8 if (ZIP==8016|ZIP==8033)
	replace DistRough`var' = 9 if (ZIP==8027|ZIP==8030)
	replace DistRough`var' = 10 if (ZIP==8005|ZIP==8018|ZIP==8019|ZIP==8020|ZIP==8026)

}

drop ZIP

* define label for Barcelona districts
#d;
	la def BCNDist 1 "Ciutat Vella" 2 "Eixample" 3 "Sants-Montjuïc"
	4 "Les Corts" 5 "Sarrià - Sant Gervasi" 6 "Gràcia"
	7 "Horta-Guinardó" 8 "Nou Barris" 9 "Sant Andreu" 10 "Sant Martí" 
	99 "Outside BCN"
	;
#d cr

la val DistRoughNET BCNDist
la val DistRough BCNDist
la var DistRoughNET "District (based on ZIP) (Netquest Data)"
la var DistRough "District (based on ZIP)"

* age
destring YBirth, replace force

g Age = 2020 - YBirth
la var Age "Age"

* discrepancies
	* Not in BCN accrording to Netquest
g NotBCNNET = (PropZIPNET <= 8000 | PropZIPNET > 8042)
la var NotBCNNET "Not from BCN According to Netquest"
g NotBCN = (PropZIP <= 8000 | PropZIP > 8042)
la var NotBCN "Not from BCN According to Survey"
	* wrong gender
g WrongGenderNET = ((FemaleNET==1 & Gender!="Mujer" | FemaleNET==0 & Gender=="Mujer") & Completed==1)
la var WrongGenderNET "Gender does not coincide"
	* wrong ZIP
g WrongZIPNET = (PropZIP != PropZIPNET & Completed==1)
la var WrongZIPNET "Wrong ZIP According to Netquest"
	* wrong age (within 3 year window)
g WrongAgeNET = (Age > AgeNET + 2 & Completed==1)
replace WrongAgeNET = 1 if (Age + 2 < AgeNET & Completed==1)
la var WrongAgeNET "Wrong Age According to Netquest"

* problematic?
g problematic = (WrongGenderNET==1|WrongZIPNET==1|WrongAgeNET)
la var problematic "Potentially problematic"

* netquest age
drop Age
rename AgeNET Age
la var Age "Age"

rename YBirth YBirthSUR
g YBirth = YBirthSUR
replace YBirth = 2020 - Age if WrongAgeNET==1
la var YBirth "Year of Birth"
drop YBirthSUR

* keep completed surveys
drop Finished
destring Progress, force replace
g Finished = (Progress >= 97)
drop if Finished == 0
drop if regexm(ConsentFinal,"No, no quiero")==1

* drop previews
drop if DistributionChannel=="preview"
drop DistributionChannel

* drop unnecessary vars
#d;
	local varsdrop Consent* *NPS* Status ResponseId IPAddress Location*
	Recipient* ExternalRef* RecordedDate Progress Q_URL Q_Language
	RandomID
	;
#d cr
drop `varsdrop'

egen RandomID = group(ticket)

* one person completed the survey twice - only keep first time
#d;
drop if ticket == "23c2cfc9486d57f4_b08aa4693f2132a7_78f448851661ac13_98c97206c890f121c312368bdc460a42"
	& Durationinseconds==1102
	;
#d cr

* vars with decimals
foreach var in MobilityPoorQ1Q1 MobilityPoorQ1Q5 {

	replace `var' = subinstr(`var', ",", ".",.) 

}

* destring
#d;
	local varsdestring *Duration* /**Lat* *Long**/ *Time_* *ZIP *Years
	HHAd* Inc* PropSq* Treat* PrefRed Happy TrustPol Luck Opti* Ideology
	YBirth ImmPerc* TimeNeigh*
	HHNum PercMedIncNeigh MobilityPoor* PrefRed2 GovSpending* PercIncRankKid*
	Tenure* MonthUnemp
	;
#d cr

destring `varsdestring', force replace

* yes/no label
la def yes 1 "Yes" 0 "No"

* small fix
replace PropYears=6 if PropYears==2014
replace problematic = 1 if PropYears > Age + 2 & PropYears!=.
replace PropYears = Age if PropYears > Age & PropYears!=.

* income
la var IncPers "Personal Income (EUR)"
la var IncHH "HH Income (EUR)"
la var IncPerAdult "Income per Adult (EUR)"
la var HHAdults "HH Adults"

* neighborhood perception
rename TimeNeighprimeBCN2_PageSubmit TimeNeighprime
la var TimeNeighprime "Time in Neighborhood Prime Question"
drop TimeNeighprime*_*

* correct answers in neighborhood prime
g NeighPExpCorr = (regexm(ExpHBCN, "^Sarri")==1)
replace NeighPExpCorr = . if Group=="C1"
g NeighPCheapCorr = (regexm(CheapHBCN, "^Nou Barris")==1)
replace NeighPCheapCorr = . if Group=="C1"
g NeighPCorr = (NeighPExpCorr==1 & NeighPCheapCorr==1)
replace NeighPCorr = . if Group=="C1"

la var NeighPExpCorr "Neigh Prime - Exp House Q correct"
la var NeighPCheapCorr "Neigh Prime - Cheap House Q correct"
la var NeighPCorr "Neigh Prime - Both answers correct"

* neighborhood prime dummy
g InfoTreatNeigh = (Group=="T1")
la var InfoTreatNeigh "Treated Neighborhood Primed"
drop Group

* perc income rank
rename IncRankTime_PageSubmit TimeIncRankTime
la var TimeIncRankTime "Time in Income Rank Q"
drop IncRankTime_*
la var IncRankPerc "Perceived Income Rank"

* Perceived Income Distribution
rename IncTilesTime_PageSubmit TimeIncTiles
drop IncTilesTime_*
* questions
rename IncTilesPerc_4 IncTilesPerc_p10
rename IncTilesPerc_5 IncTilesPerc_p30
rename IncTilesPerc_6 IncTilesPerc_p50
rename IncTilesPerc_7 IncTilesPerc_p70
rename IncTilesPerc_8 IncTilesPerc_p90
rename IncTilesPerc_9 IncTilesPerc_p99
* label
foreach tile in 10 30 50 70 90 99 {
	la var IncTilesPerc_p`tile' "Perceived Income from HH in Pctile `tile'"
}
* adjustment
replace IncTilesPerc_p10 = 1 if IncTilesPerc_p10 == 0

* inconsistent answers
g IncIncome = (IncRankPerc >= 10 & (IncPerAdult + 100 < IncTilesPerc_p10))
replace IncIncome = 1 if (IncRankPerc >= 30 & (IncPerAdult + 200 < IncTilesPerc_p30))
replace IncIncome = 1 if (IncRankPerc >= 50 & (IncPerAdult + 300 < IncTilesPerc_p50))
replace IncIncome = 1 if (IncRankPerc >= 70 & (IncPerAdult + 400 < IncTilesPerc_p70))
replace IncIncome = 1 if (IncRankPerc >= 90 & (IncPerAdult + 500 < IncTilesPerc_p90))
la var IncIncome "Inconsistent Income Distribution"

* perc median income neihborhood
la var PercMedIncNeigh "Perceived Med Inc in Neighborhood"

* pyramid	
g Pyramid = .
replace Pyramid = 1 if regexm(PyramidQ,"Tipo A")==1
replace Pyramid = 2 if regexm(PyramidQ,"Tipo B")==1
replace Pyramid = 3 if regexm(PyramidQ,"Tipo C")==1
replace Pyramid = 4 if regexm(PyramidQ,"Tipo D")==1
replace Pyramid = 5 if regexm(PyramidQ,"Tipo E")==1
la var Pyramid "Pyramid"
la def Pyramid 1 "Type A" 2 "Type B" 3 "Type C" 4 "Type D" 5 "Type E"
la val Pyramid Pyramid

* info treatment
g InfoTreatInc = (Group2=="T2")
drop Group2
la var InfoTreatInc "Income Information Treatment"
g TimeInfoTreatInc = .
la var TimeInfoTreatInc "Treatment Exposure (seconds)"
foreach pct in 0 10 20 30 40 50 60 70 80 90 {
	replace TimeInfoTreatInc = TreatPct`pct'Time_PageSubmit if TreatPct`pct'Time_PageSubmit != .
}

* add actual income distribution data
cross using "$data/int/income_pctiles.dta"
keep if inrange(IncPerAdult,IncTrhldMonth_l,IncTrhldMonth_u)
* drop unnecessary vars
drop GHH* NHH*
* rename
rename IncTrhldMonth_l IncTrhldMont_l_Pctil
rename IncTrhldMonth_u IncTrhldMonth_u_Pctil
rename pctile IncRankAct
la var IncRankAct "Actual Income Rank"
* income rank perceived 1-99
replace IncRankPerc = 1 if IncRankPerc == 0
replace IncRankPerc = 99 if IncRankPerc == 100
* rank misperception
g InkRankMisp = IncRankPerc - IncRankAct
la var InkRankMisp "Income Rank Misperception"
* drop treatment variables
drop TreatPct*Time*

* preferences for redistribution
g PrefRedScaled = ((PrefRed * (-1)) + 10)
la var PrefRedScaled "Preferences for Redistribution"
la var PrefRed "Preferences for Redistribution (0-10), 0 max redistribution"	

* gov spending
rename GovSpending_1 GovSpending_Defs
rename GovSpending_2 GovSpending_Infr
rename GovSpending_3 GovSpending_Educ
rename GovSpending_4 GovSpending_Heal
rename GovSpending_5 GovSpending_SSAs
rename GovSpending_7 GovSpending_SSPe
la var GovSpending_Defs "Gov Spending: Defense"
la var GovSpending_Infr "Gov Spending: Infraestructure"
la var GovSpending_Educ "Gov Spending: Education"
la var GovSpending_Heal "Gov Spending: Health"
la var GovSpending_SSAs "Gov Spending: Assistance"
la var GovSpending_SSPe "Gov Spending: Pensions"
foreach var in Defs Infr Educ Heal SSAs SSPe {
	replace GovSpending_`var' = round(GovSpending_`var' / 100, .01)
}

* trust
la var TrustPol "Trust in Politicians (0-10)"

* Luck 
la var Luck "POUM: Effort vs Luck (0-10)"

* perc inc rank as kid
rename PercIncRankKid_1 PercIncRankKid
la var PercIncRankKid "Perceived Income Rank as a Child"

* subjective mobility
rename Optimism10_1 PercIncRank10yrs
la var PercIncRank10yrs "POUM: Perc Inc Rank in 10 years"

* lack of mobility
replace MobilityPoorQ1Q1 = round(MobilityPoorQ1Q1 / 100, .001)
la var MobilityPoorQ1Q1 "POUM: Q1 to Q1"
	
* american dream
replace MobilityPoorQ1Q5 = round(MobilityPoorQ1Q5 / 100, .001)
la var MobilityPoorQ1Q5 "POUM: Q1 to Q5"
replace MobilityPoorQ1Q5 = 0.2 if RandomID==324

* ideology
la var Ideology "Ideology: Left vs Right (0-10)"

* party
g Party = upper(Party19)
replace Party = "" if (regexm(Party19,"No vot")==1)
replace Party = "OTHER" if (regexm(Party19,"Otro")==1)
la var Party "Party Nov 19"

* voted
g Voted = (regexm(Party19,"No vot")==0)
la var Voted "Voted"
la val Voted yes
replace Voted = . if Party19 == "NS/NC"

* party dummies
g PSOE = (Party=="PSOE")
g PODEMOS = (Party=="PODEMOS")
g PP = (Party == "PP")
g CS = (Party=="CIUDADANOS")
g VOX = (Party=="VOX")
foreach party in PSOE PODEMOS PP CS VOX {
	replace `party' = . if (Voted == 0 | Voted == .)
	la var `party' "Voted `party' (Nov-19)"

}

* religion
g Religious = (regexm(Religion,"Católico|Creyente de")==1)
la val Religious yes
la var Religious "Religious"
drop Religion

* social interactions
g t_SocInt_Family = TimeShr2_1
g t_SocInt_ChildhoodF = TimeShr2_2
g t_SocInt_Friends = TimeShr2_3
g t_SocInt_Neighbors = TimeShr2_4
g t_SocInt_WorkColl = TimeShr2_5

#d;
	la def SocInt 1 "Almost every day" 2 "Several times a week"
	3 "Several times a month" 4 "Once a month"
	5 "Several times a year" 6 "Once a year"
	7 "Never"
	;
#d cr

foreach group in Family ChildhoodF Friends Neighbors WorkColl {
	g SocInt_`group' = .
	replace SocInt_`group' = 1 if regexm(t_SocInt_`group',"Casi todos los")==1
	replace SocInt_`group' = 2 if regexm(t_SocInt_`group',"Varias veces a la semana")==1
	replace SocInt_`group' = 3 if regexm(t_SocInt_`group',"Varias veces al mes")==1
	replace SocInt_`group' = 4 if regexm(t_SocInt_`group',"Una vez al mes")==1
	replace SocInt_`group' = 5 if regexm(t_SocInt_`group',"Varias veces al a")==1
	replace SocInt_`group' = 6 if regexm(t_SocInt_`group',"Una vez al a")==1
	replace SocInt_`group' = 7 if regexm(t_SocInt_`group',"Nunca")==1
	cap drop t_SocInt_`group'
	la val SocInt_`group' SocInt
}

la var SocInt_Family "Social interactions with close family"
la var SocInt_ChildhoodF "Social interactions with childhood friends"
la var SocInt_Friends "Social interactions with friends"
la var SocInt_Neighbors "Social interactions with neighbors"
la var SocInt_WorkColl "Social interactions with work colleagues"

* drop old variables
drop TimeShr2_*

* changes with COVID-19
g t_SI_COVID_Family = TimeShrCOVID19_1
g t_SI_COVID_ChildhoodF = TimeShrCOVID19_2
g t_SI_COVID_Friends = TimeShrCOVID19_3
g t_SI_COVID_Neighbors = TimeShrCOVID19_4
g t_SI_COVID_WorkColl = TimeShrCOVID19_5

#d;
	la def SocIntChng 1 "Much less frequent" 2 "Somewhat less frequent"
	3 "Have not changed" 4 "Somewhat more frequent"
	5 "Much more frequent" 
	;
#d cr

* gen vars
foreach group in Family ChildhoodF Friends Neighbors WorkColl {
	g SI_COVID_`group' = .
	replace SI_COVID_`group' = 1 if regexm(t_SI_COVID_`group',"mucho menos")==1
	replace SI_COVID_`group' = 2 if regexm(t_SI_COVID_`group',"algo menos")==1
	replace SI_COVID_`group' = 3 if regexm(t_SI_COVID_`group',"no han cambiado")==1
	replace SI_COVID_`group' = 4 if regexm(t_SI_COVID_`group',"algo más")==1
	replace SI_COVID_`group' = 5 if regexm(t_SI_COVID_`group',"mucho más")==1
	cap drop t_SI_COVID_`group'
	* label
	la val SI_COVID_`group' SocIntChng
}

* label
la var SI_COVID_Family "Social interactions with close family during COVID-19"
la var SI_COVID_ChildhoodF "Social interactions with childhood friends during COVID-19"
la var SI_COVID_Friends "Social interactions with friends during COVID-19"
la var SI_COVID_Neighbors "Social interactions with neighbors during COVID-19"
la var SI_COVID_WorkColl "Social interactions with work colleagues during COVID-19"

* drop old vars
drop TimeShrCOVID19_*

* friends from other social classes
replace RefGSocClass = "1" if regexm(RefGSocClass,"todas las clases")==1
replace RefGSocClass = "2" if regexm(RefGSocClass,"clase obrera")==1
replace RefGSocClass = "3" if regexm(RefGSocClass,"clase media")==1
replace RefGSocClass = "4" if regexm(RefGSocClass,"clase alta")==1

#d;
	la def SocClass 1 "All Social Classes" 2 "Mostly Working Class" 
	3 "Mostly Middle Class" 4 "Mostly Upper Class"
	;
#d cr

destring RefGSocClass, force replace
la var RefGSocClass "Social Groups Interactions"
la val RefGSocClass SocClass

* social networks
replace HasSNAcc = "1" if HasSNAcc=="Sí" 
replace HasSNAcc = "0" if HasSNAcc=="No"
destring HasSNAcc, force replace
la val HasSNAcc yes

* intensity of use
replace SNUse = "1" if regexm(SNUse,"Todos")==1
replace SNUse = "2" if regexm(SNUse,"5-6")==1
replace SNUse = "3" if regexm(SNUse,"3-4")==1
replace SNUse = "4" if regexm(SNUse,"1-2")==1
replace SNUse = "5" if regexm(SNUse,"Casi nunca")==1

#d;
	la def SNUse 1 "Everyday" 2 "5-6 days per week" 3 "3-4 days per week"
	4 "1-2 days per week" 5 "Almost never"
	;
#d cr

destring SNUse, force replace
la val SNUse SNUse
la var SNUse "Social Networks Use"
	
* information acquisition
replace NewsInf = "1" if regexm(NewsInf,"Todos")==1
replace NewsInf = "2" if regexm(NewsInf,"5-6")==1
replace NewsInf = "3" if regexm(NewsInf,"3-4")==1
replace NewsInf = "4" if regexm(NewsInf,"1-2")==1
replace NewsInf = "5" if regexm(NewsInf,"no tiene tiempo")==1
replace NewsInf = "6" if regexm(NewsInf,"no le interesan")==1

#d;
	la def NewsInf 1 "Everyday" 2 "5-6 days per week" 3 "3-4 days per week"
	4 "1-2 days per week" 5 "Never bc no time" 6 "Never bc no interest"
	;
#d cr

destring NewsInf, force replace
la val NewsInf NewsInf
la var NewsInf "Frequency of checking the news"

* media
la var MediaUse "Media Use"

* gender
g Female = (Gender=="Mujer")
la def Female 1 "Female" 0 "Male"
la val Female Female
la var Female "Female"
drop Gender
drop FemaleNET

* birth
la var YBirth "Year of Birth"

* country
replace Orig = lower(Orig)
g OriginCtry = ""
replace OriginCtry = "ESP" if regexm(Orig,"espa|spain|barcelona|aspnya|ezpa|eapa|epaña|espñ|esp")==1
replace OriginCtry = "CAT" if regexm(Orig,"catal|catlunya")==1
replace OriginCtry = "POR" if regexm(Orig,"portugal")==1
replace OriginCtry = "GBR" if regexm(Orig,"inglaterra|uk")==1
replace OriginCtry = "FRA" if regexm(Orig,"franc")==1
replace OriginCtry = "ITA" if regexm(Orig,"italia|sicily")==1
replace OriginCtry = "DEU" if regexm(Orig,"alem[a]*[á]*n")==1
replace OriginCtry = "BEL" if regexm(Orig,"belgica")==1
replace OriginCtry = "DNK" if regexm(Orig,"dinama")==1
replace OriginCtry = "NLD" if regexm(Orig,"paises bajos")==1
replace OriginCtry = "ROU" if regexm(Orig,"romania|rumania")==1
replace OriginCtry = "HRV" if regexm(Orig,"croacia")==1
replace OriginCtry = "UKR" if regexm(Orig,"ucrania")==1
replace OriginCtry = "BGR" if regexm(Orig,"bulgaria")==1
replace OriginCtry = "RUS" if regexm(Orig,"rusia|russia")==1
replace OriginCtry = "LTU" if regexm(Orig,"lituania")==1
replace OriginCtry = "HUN" if regexm(Orig,"hungria")==1
replace OriginCtry = "POL" if regexm(Orig,"polonia")==1
replace OriginCtry = "MKD" if regexm(Orig,"macedonia")==1
replace OriginCtry = "AND" if regexm(Orig,"andorra")==1
replace OriginCtry = "CHE" if regexm(Orig,"suiza")==1
replace OriginCtry = "BOL" if regexm(Orig,"bolivia")==1
replace OriginCtry = "MEX" if regexm(Orig,"m[e]*[é]*xico")==1
replace OriginCtry = "PRY" if regexm(Orig,"paraguay")==1
replace OriginCtry = "PER" if regexm(Orig,"per[\ú]*[u]*")==1
replace OriginCtry = "CHL" if regexm(Orig,"chile")==1
replace OriginCtry = "ECU" if regexm(Orig,"ecuador")==1
replace OriginCtry = "VEN" if regexm(Orig,"venezuela")==1
replace OriginCtry = "COL" if regexm(Orig,"colombia")==1
replace OriginCtry = "NIC" if regexm(Orig,"nicaragua")==1
replace OriginCtry = "CUB" if regexm(Orig,"cuba")==1
replace OriginCtry = "DOM" if regexm(Orig,"dominicana")==1
replace OriginCtry = "HND" if regexm(Orig,"honduras")==1
replace OriginCtry = "GTM" if regexm(Orig,"guatemala")==1
replace OriginCtry = "SLV" if regexm(Orig,"salvador")==1
replace OriginCtry = "BRA" if regexm(Orig,"brasil|brazil")==1
replace OriginCtry = "ARG" if regexm(Orig,"argentina")==1
replace OriginCtry = "URY" if regexm(Orig,"uruguay")==1
replace OriginCtry = "AUS" if regexm(Orig,"australia")==1
replace OriginCtry = "NPL" if regexm(Orig,"nepal")==1
replace OriginCtry = "PHL" if regexm(Orig,"filipinas")==1
replace OriginCtry = "ARM" if regexm(Orig,"armenia")==1
replace OriginCtry = "KOR" if regexm(Orig,"corea")==1
replace OriginCtry = "IND" if regexm(Orig,"india")==1
replace OriginCtry = "MAR" if regexm(Orig,"marruecos")==1
la var OriginCtry "Country of Origin"
drop Orig

* foreign
g ForeignBorn = (OriginCtry!="ESP" & OriginCtry!="CAT")
la val ForeignBorn yes
la var ForeignBorn "Foreign Born"
	
* civil status
g Married = (regexm(CivilStat,"Casado")==1)
la var Married "Married"
la val Married yes

replace CivilStat = "1" if (regexm(CivilStat,"Casado")==1)
replace CivilStat = "2" if (regexm(CivilStat,"Soltero")==1)
replace CivilStat = "3" if (regexm(CivilStat,"Viudo")==1)
replace CivilStat = "4" if (regexm(CivilStat,"Separado")==1)
replace CivilStat = "5" if (regexm(CivilStat,"Divorcia")==1) 
replace CivilStat = "9" if (regexm(CivilStat,"NS[\/]NC")==1) 
la var CivilStat "Civil Status"

destring CivilStat, force replace
la def CivilStat 1 "Married" 2 "Single" 3 "Widow" 4 "Separated" 5 "Divorced" 9 "NA/NR"
la val CivilStat CivilStat

* kids
replace NChild = "0" if NChild=="No tiene hijos"
replace NChild = "4" if NChild=="Más de 3"
la var NChild "Number of Children"
destring NChild, force replace

* university
g University = (regexm(Educ,"ios universitarios")==1)
la var University "University"
la val University yes

* general education
replace Educ = "0" if regexm(Educ,"No ha ido a la escuela")==1
replace Educ = "1" if regexm(Educ,"Ha ido a la escuela menos de")==1
replace Educ = "2" if regexm(Educ,"n primaria")==1
replace Educ = "3" if regexm(Educ,"n secundaria")==1
replace Educ = "4" if regexm(Educ,"n profesional")==1
replace Educ = "5" if regexm(Educ,"ios universitarios")==1
replace Educ = "9" if regexm(Educ,"NS[\/]NC")==1
destring Educ, force replace
#d;
	la def Educ 0 "No schooling" 1 "Less than 5 years"
	2 "Primary education" 3 "Secondary education" 4 "Professional degree"
	5 "University" 9 "NA/NR"
	;
#d cr
la val Educ Educ
la var Educ "Education"

* employment
replace EmpStat = "1" if (regexm(EmpStat,"sector privado")==1)
replace EmpStat = "2" if (regexm(EmpStat,"sector público")==1)
replace EmpStat = "3" if (regexm(EmpStat,"autónomo")==1)
replace EmpStat = "4" if (regexm(EmpStat,"ha trabajado antes")==1)
replace EmpStat = "5" if (regexm(EmpStat,"busca su primer empleo")==1)
replace EmpStat = "6" if (regexm(EmpStat,"Estudiante")==1)
replace EmpStat = "7" if (regexm(EmpStat,"Jubilado")==1)
replace EmpStat = "8" if (regexm(EmpStat,"Trabajo dom")==1)
replace EmpStat = "9" if (regexm(EmpStat,"Otra")==1)
* label
la var EmpStat "Employment Status"
destring EmpStat, force replace
#d;
la def Emp 1 "Works (Private Sector)" 
	2 "Works (Public Sector)"
	3 "Works (Self-Employed)" 
	4 "Unemployed and has worked before" 
	5 "Unemployed looking for the first job" 
	6 "Student" 
	7 "Retired"
	8 "Domestic Work" 
	9 "Other"
	;
#d cr
la val EmpStat Emp

* employed
g Employed = (EmpStat<=3)
la var Employed "Employed"
la val Employed yes

* retired
g Retired = (EmpStat==7)
la var Retired "Retired"
la val Retired yes

* unemployed
g Unemployed = (EmpStat==4|EmpStat==5)
la var Unemployed "Unemployed"
la val Unemployed yes

* domestic work
g DomWork = (EmpStat==8)
la var DomWork "Domestic Work/Home Production"
la val DomWork yes

* occupation
foreach var in Occupation OccupationOld {

replace `var' = "1" if regexm(`var',"Directores")
replace `var' = "2" if regexm(`var',"salud y la ense")
replace `var' = "3" if regexm(`var',"intelectuales")
replace `var' = "4" if regexm(`var',"profesionales de apoyo")
replace `var' = "5" if regexm(`var',"oficina que no atienden")
replace `var' = "6" if regexm(`var',"que atienden al")
replace `var' = "7" if regexm(`var',"restauración")
replace `var' = "8" if regexm(`var',"salud y cuidado")
replace `var' = "9" if regexm(`var',"protección y seguridad")
replace `var' = "10" if regexm(`var',"agrícola, ganadero")
replace `var' = "11" if regexm(`var',"cualificados de la construcción")
replace `var' = "12" if regexm(`var',"cualificados de las industrias")
replace `var' = "13" if regexm(`var',"maquinaria fijas")
replace `var' = "14" if regexm(`var',"maquinaria móvil")
replace `var' = "15" if regexm(`var',"no cualificados en servicios")
replace `var' = "16" if regexm(`var',"Peones")
replace `var' = "17" if regexm(`var',"militares")

}

destring Occupation OccupationOld, force replace

* new occupation variable
g Occ = Occupation
replace Occ = OccupationOld if Occ ==. & OccupationOld!=.
la var Occ "Occupation"
* label occupation
#d;
	la def Occ 1 "A. Directores y gerentes"
	2 "B. Técnicos y profesionales científicos e intelectuales de la salud y la enseñanza"
	3 "C. Otros técnicos y profesionales científicos e intelectuales"
	4 "D. Técnicos y profesionales"
	5 "E. Empleados de oficina que no atienden al público"
	6 "F. Empleados de oficina que atienden al público"
	7 "G. Trabajadores de los servicios de restauración y comercio"
	8 "H. Trabajadores de los servicios de salud y cuidado de personas"
	9 "I. Trabajadores de los servicios de protección y seguridad"
	10 "J. Trabajadores cualificados en el sector agrícola, ganadero, forestal y pesquero"
	11 "K. Trabajadores cualificados de la construcción"
	12 "L. Trabajadores cualificados de las industrias manufactureras"
	13 "M. Operadores de instalaciones y maquinarias fijas"
	14 "N. Conductores y operadores de maquinaria móvil"
	15 "O. Trabajadores no cualificados en servicios"
	16 "P. Peones de la agricultura, pesca, construcción, industrias manufactureras y transportes"
	17 "Q. Ocupaciones militares" 
	;
#d cr
la val Occupation Occ
la val OccupationOld Occ
la val Occ Occ

* occupation group
g cno11 = ""
replace cno11 = "A" if Occ==1
replace cno11 = "B" if Occ==2
replace cno11 = "C" if Occ==3
replace cno11 = "D" if Occ==4
replace cno11 = "E" if Occ==5
replace cno11 = "F" if Occ==6
replace cno11 = "G" if Occ==7
replace cno11 = "H" if Occ==8
replace cno11 = "I" if Occ==9
replace cno11 = "J" if Occ==10
replace cno11 = "K" if Occ==11
replace cno11 = "L" if Occ==12
replace cno11 = "M" if Occ==13
replace cno11 = "N" if Occ==14
replace cno11 = "O" if Occ==15
replace cno11 = "P" if Occ==16
replace cno11 = "Q" if Occ==17
la var cno11 "Occupation Group (CNO-11)"

* months unemployed
la var MonthUnemp "Months Unemployed"

* employment loss
g ReasonUnemp = .
replace ReasonUnemp = 1 if regexm(EmpLossVirus,"Despido")==1
replace ReasonUnemp = 2 if regexm(EmpLossVirus,"Fin del")==1
replace ReasonUnemp = 3 if regexm(EmpLossVirus,"Enfermedad")==1
replace ReasonUnemp = 4 if regexm(EmpLossVirus,"Realizar estudios")==1
replace ReasonUnemp = 5 if regexm(EmpLossVirus,"Motivos familiares")==1
replace ReasonUnemp = 6 if regexm(EmpLossVirus,"COVID")==1
#d;
	la def EmpLoss 1 "Layoff" 2 "End of Contract" 3 "Sickness" 4 "Formation"
	5 "Family Reasons" 6 "COVID-19"
	;
#d cr
la val ReasonUnemp EmpLoss
la var ReasonUnemp "Reason Employment Loss"
drop EmpLossVirus

* commute
foreach t in Now Bef1 Bef2 PostCOVID {

	replace Commute`t' = "1" if regexm(Commute`t',"Transporte p")==1
	replace Commute`t' = "2" if regexm(Commute`t',"Taxi")==1
	replace Commute`t' = "3" if regexm(Commute`t',"Veh")==1
	replace Commute`t' = "4" if regexm(Commute`t',"Caminando")==1
	replace Commute`t' = "5" if regexm(Commute`t',"desde casa")==1
	
}
destring Commute*, force replace

* general commuting
g Commute = CommuteNow
replace Commute = CommuteBef1 if Commute == . & CommuteBef1 != .
replace Commute = CommuteBef2 if Commute == . & CommuteBef2 != .
la var Commute "Commuting to Work"
la def Commute 1 "Public Transportation" 2 "Taxi" 3 "Private vehicle" 4 "Walking" 5 "Work from Home"
la val Commute Commute
la val CommutePostCOVID Commute

* commute COVID-19
replace CommutePostCOVID = 5 if CommuteNow==5
rename CommutePostCOVID CommuteCOVID
la var CommuteCOVID "Commute during COVID-19"

drop CommuteNow CommuteBef*

* workplace
foreach t in Now Bef {

	replace WorkDistrict`t' = "1" if regexm(WorkDistrict`t',"Vella")==1
	replace WorkDistrict`t' = "2" if regexm(WorkDistrict`t',"Eixample")==1
	replace WorkDistrict`t' = "3" if regexm(WorkDistrict`t',"Sants")==1
	replace WorkDistrict`t' = "4" if regexm(WorkDistrict`t',"Corts")==1
	replace WorkDistrict`t' = "5" if regexm(WorkDistrict`t',"Sant Gervasi")==1
	replace WorkDistrict`t' = "6" if regexm(WorkDistrict`t',"Gràcia")==1
	replace WorkDistrict`t' = "7" if regexm(WorkDistrict`t',"Horta")==1
	replace WorkDistrict`t' = "8" if regexm(WorkDistrict`t',"Nou Barris")==1
	replace WorkDistrict`t' = "9" if regexm(WorkDistrict`t',"Sant Andreu")==1
	replace WorkDistrict`t' = "10" if regexm(WorkDistrict`t',"Sant Martí")==1

}
destring WorkDistrictNow WorkDistrictBef, force replace

* work district
g WorkDistrict = WorkDistrictNow
replace WorkDistrict = WorkDistrictBef if WorkDistrict==. & WorkDistrictBef != .
replace WorkDistrict = 99 if WorkDistrict == .
la var WorkDistrict "Barcelona Work/Study District"

la val WorkDistrict BCNDist

* working or having worked in Barcelona
g WorkBCN = (WorkDistrict != 99)
la val WorkBCN yes
la var WorkBCN "Works, Has Worked, or Studies in Barcelona"

* work city
g WorkCity = WorkCityNow
replace WorkCity = WorkCityBef if WorkCityBef != "" & WorkCity == ""
replace WorkCity = "BARCELONA" if WorkBCN==1 & WorkCity == ""
la var WorkCity "Work City"

foreach var in WorkCity {

* upper case
replace `var' = subinstr(`var',"Ñ","N",.)
replace `var' = subinstr(`var',"Ç","C",.)
replace `var' = subinstr(`var',"Á","A",.)
replace `var' = subinstr(`var',"À","A",.)
replace `var' = subinstr(`var',"Ä","A",.)
replace `var' = subinstr(`var',"È","E",.)
replace `var' = subinstr(`var',"É","E",.)
replace `var' = subinstr(`var',"Í","I",.)
replace `var' = subinstr(`var',"Ó","O",.)
replace `var' = subinstr(`var',"Ò","O",.)
replace `var' = subinstr(`var',"Ö","O",.)
replace `var' = subinstr(`var',"Ú","U",.)
replace `var' = subinstr(`var',"Ù","U",.)
replace `var' = subinstr(`var',"Ü","U",.)
* lower case
replace `var' = subinstr(`var',"ñ","n",.)
replace `var' = subinstr(`var',"ç","c",.)
replace `var' = subinstr(`var',"á","a",.)
replace `var' = subinstr(`var',"à","a",.)
replace `var' = subinstr(`var',"ä","a",.)
replace `var' = subinstr(`var',"è","e",.)
replace `var' = subinstr(`var',"é","e",.)
replace `var' = subinstr(`var',"í","i",.)
replace `var' = subinstr(`var',"ï","i",.)
replace `var' = subinstr(`var',"ó","o",.)
replace `var' = subinstr(`var',"ò","o",.)
replace `var' = subinstr(`var',"ö","o",.)
replace `var' = subinstr(`var',"ú","u",.)
replace `var' = subinstr(`var',"ù","u",.)
replace `var' = subinstr(`var',"ü","u",.)
* put everything upper case
replace `var' = upper(`var')
* remove leading and trailing blanks
replace `var' = strtrim(`var')
replace `var' = strltrim(`var')

}

* small corrections
replace WorkDistrict = 3 if WorkCity=="ZONA FRANCA"
replace WorkBCN = 1 if WorkCity=="ZONA FRANCA"
* barcelona
#d;
replace WorkCity = "BARCELONA" if (WorkCity=="NO"|
	WorkCity=="CIUDAD VELLA"|WorkCity=="CIUTAT VELLA"|WorkCity=="EIXAMPLE"
	|WorkCity=="EXAMPLE"|WorkCity=="HORTA"|WorkCity=="POBLE NOU"
	|WorkCity=="SARRIA"|WorkCity=="ZONA FRANCA")
	;
#d cr

* drop unnecessary variables
drop WorkDistrictNow WorkDistrictBef WorkCityNow WorkCityBef

* perc immigration country
replace ImmPercCtry = round(ImmPercCtry / 100 , .01)
la var ImmPercCtry "Perceived Immigration Share in the Country"

* perc immigration neighborhood
replace ImmPercNeigh = round(ImmPercNeigh / 100 , .01)
la var ImmPercNeigh "Perceived Immigration Share in the Neighborhood"
drop ImmTime_*

* address
* city
g City = PropLocCity
la var City "City"
* StreetType
g StreetType = PropStType
replace StreetType = "CL" if PropStType=="Calle"
replace StreetType = "AV" if PropStType=="Avenida"
replace StreetType = "PS" if PropStType=="Paseo"
replace StreetType = "PZ" if PropStType=="Plaza"
replace StreetType = "RB" if PropStType=="Rambla"
replace StreetType = "RD" if PropStType=="Ronda"
replace StreetType = "TR" if PropStType=="Travesía"
replace StreetType = "CR" if PropStType=="Carretera"
replace StreetType = "PJ" if PropStType=="Pasaje"
replace StreetType = "URB" if PropStType=="Urbanización"
la var StreetType "StreeType"
* StreetName
g StreetName = PropStName
la var StreetName "Street Name"
* StreetNum
g StreetNum = PropStNum
la var StreetNum "Street Number"
* ZIPCode
g ZIPCode = PropZIP
tostring ZIPCode, replace force
replace ZIPCode = "0" + ZIPCode if length(ZIPCode)==4
la var ZIPCode "ZIP Code"

* replacing special characters
foreach var in City StreetName StreetNum Prop16yoCity {

* upper case
replace `var' = subinstr(`var',"Ñ","N",.)
replace `var' = subinstr(`var',"Ç","C",.)
replace `var' = subinstr(`var',"Á","A",.)
replace `var' = subinstr(`var',"À","A",.)
replace `var' = subinstr(`var',"Ä","A",.)
replace `var' = subinstr(`var',"È","E",.)
replace `var' = subinstr(`var',"É","E",.)
replace `var' = subinstr(`var',"Í","I",.)
replace `var' = subinstr(`var',"Ó","O",.)
replace `var' = subinstr(`var',"Ò","O",.)
replace `var' = subinstr(`var',"Ö","O",.)
replace `var' = subinstr(`var',"Ú","U",.)
replace `var' = subinstr(`var',"Ù","U",.)
replace `var' = subinstr(`var',"Ü","U",.)
* lower case
replace `var' = subinstr(`var',"ñ","n",.)
replace `var' = subinstr(`var',"ç","c",.)
replace `var' = subinstr(`var',"á","a",.)
replace `var' = subinstr(`var',"à","a",.)
replace `var' = subinstr(`var',"ä","a",.)
replace `var' = subinstr(`var',"è","e",.)
replace `var' = subinstr(`var',"é","e",.)
replace `var' = subinstr(`var',"í","i",.)
replace `var' = subinstr(`var',"ï","i",.)
replace `var' = subinstr(`var',"ó","o",.)
replace `var' = subinstr(`var',"ò","o",.)
replace `var' = subinstr(`var',"ö","o",.)
replace `var' = subinstr(`var',"ú","u",.)
replace `var' = subinstr(`var',"ù","u",.)
replace `var' = subinstr(`var',"ü","u",.)
* put everything upper case
replace `var' = upper(`var')
* remove leading and trailing blanks
replace `var' = strtrim(`var')
replace `var' = strltrim(`var')

}

* floor
g Floor = substr(StreetNum,strpos(StreetNum," ")+1,1)
replace Floor = "" if strpos(StreetNum," ")==0
la var Floor "Floor"

* door
g Door = substr(StreetNum, length(StreetNum),1)
replace Door = "" if strpos(StreetNum," ")==0
la var Door "Door"

* finish cleaning StreetNum
generate str20 clean = ustrregexra(StreetNum,`"[^0-9]"'," ")
replace StreetNum = substr(clean,1,strpos(clean," ")-1) if strpos(clean," ")!=0
drop clean

* Years in same property
la var PropYears "Years Living in Same Property"
drop PropLoc*

* property type
replace PropType = "1" if (regexm(PropType,"totalmente pagada")==1)
replace PropType = "2" if (regexm(PropType,"con pagos pendientes")==1)
replace PropType = "3" if (regexm(PropType,"herencia")==1)
replace PropType = "4" if (regexm(PropType,"alquiler")==1 & regexm(PropType,"social")==0)
replace PropType = "5" if (regexm(PropType,"gratis")==1)
replace PropType = "6" if (regexm(PropType,"alquiler social")==1)
destring PropType, force replace
* label
la var PropType "Property Type"
#d;
	la def Prop 1 "Owned, Fully Paid" 2 "Owned, Pending Payments"
	3 "Owned, Bequest or Donation"
	4 "Rental" 5 "Ceded free or at a low price"
	6 "Social Rental"
	;
#d cr
la val PropType Prop

* perc housing size
la var PropSqm "Perceived Prop Sqm"
rename PropSqm PropSqmPerc

* bough/rented house
replace BoughtHouse = "1" if BoughtHouse== "Sí"
replace BoughtHouse = "0" if BoughtHouse== "No"
replace RentedHouse = "1" if RentedHouse== "Sí"
replace RentedHouse = "0" if RentedHouse== "No"
destring RentedHouse BoughtHouse, force replace
la val BoughtHouse yes
la val RentedHouse yes

* reasons to buy/rent
g ReasonHouse_Work = 0
g ReasonHouse_Family = 0
g ReasonHouse_NeighAmen = 0
g ReasonHouse_Neighbors = 0
g ReasonHouse_Price = 0
g ReasonHouse_Connected = 0
g ReasonHouse_Safe = 0
g ReasonHouse_Partner = 0
g ReasonHouse_RelativeOwn = 0

foreach var in ReasonHouseBuy ReasonHouseRent ReasonsHouseOther {

	replace ReasonHouse_Work = 1 if regexm(`var', "trabajo o centro") == 1
	replace ReasonHouse_Family = 1 if regexm(`var', "domicilio de un familiar") == 1
	replace ReasonHouse_NeighAmen = 1 if regexm(`var', "escuelas") == 1
	replace ReasonHouse_Neighbors = 1 if regexm(`var', "vecinos") == 1
	replace ReasonHouse_Price = 1 if regexm(`var', "Precio") == 1
	replace ReasonHouse_Connected = 1 if regexm(`var', "transporte") == 1
	replace ReasonHouse_Safe = 1 if regexm(`var', "seguro") == 1
	replace ReasonHouse_Partner = 1 if regexm(`var', "pareja") == 1
	replace ReasonHouse_RelativeOwn = 1 if regexm(`var', "familiar directo") == 1

}
la var ReasonHouse_Work "Reason Dwelling: Close to Work"
la var ReasonHouse_Family "Reason Dwelling: Close to Family"
la var ReasonHouse_NeighAmen "Reason Dwelling: Neighborhood Amenities"
la var ReasonHouse_Neighbors "Reason Dwelling: Neighbors"
la var ReasonHouse_Price "Reason Dwelling: Price"
la var ReasonHouse_Connected "Reason Dwelling: Well Connected"
la var ReasonHouse_Safe "Reason Dwelling: Neighborhood Safety"
la var ReasonHouse_Partner "Reason Dwelling: Partner's dwelling"
la var ReasonHouse_RelativeOwn "Reason Dwelling: Relative Owned"
la val ReasonHouse_* yes

* Same dwelling 16yo
g SameProp16yo = (regexm(Prop16yo,"S")==1)
la var SameProp16yo "Lived in the same property at age 16"
la val SameProp16yo yes
drop Prop16yo
* City 16yo
g City16yo = Prop16yoCity
la var City16yo "City 16yo"
* ZIPCode 16yo
g ZIPCode16yo = Prop16yoZIP
tostring ZIPCode16yo, replace force
replace ZIPCode16yo = "0" + ZIPCode16yo if length(ZIPCode16yo)==4
replace ZIPCode16yo = "" if ZIPCode16yo == "."|ZIPCode16yo == "0"|ZIPCode16yo == "1"
la var ZIPCode16yo "ZIP Code"

* person living in the same dwelling 16yo
replace City16yo = City if SameProp16yo==1
replace ZIPCode16yo = ZIPCode if SameProp16yo==1

foreach var in ZIP {
	replace Prop16yo`var' = Prop`var' if SameProp16yo==1

}
replace Prop16yoCity = "BARCELONA" if Prop16yoCity=="" & SameProp16yo==1

* drop variables not needed
#d;
	drop FirstID IncTrhld* PCT*0 Dup* Completed NotAccept 
	UserLanguage DropAddress Finished *Time_*
	ReasonHouseBuy ReasonHouseRent ReasonsHouseOther
	Prop16yoStType Prop16yoStName Prop16yoStNum Prop16yoCity Prop16yoZIP
	Dropped Q_TotalDuration HH Durationinseconds
;
#d cr

* store
compress
save "$data/survey_netquest.dta", replace

* erase temp files
cap erase "$data/temp/ticket_demographics.dta"
	
}
********************************************************************************
* closing
********************************************************************************
{
cap log close
clear

}
